package q26_removeDuplicates;

import java.util.Arrays;

public class Solution {
    public static void main(String[] args) {
        int[] nums = {1,1,2};
        System.out.println(removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }

    public static int removeDuplicates(int[] nums) {
        if (nums.length <= 1) {
            return nums.length;
        }
        int res = 0;
        int test = 1;

        // 设置两个指针，分别用来检测和替换
        for (; test < nums.length; test++) {
            if(nums[test] == nums[res]){
                continue;
            }else {
                res ++;
                nums[res] = nums[test];
            }
        }
        return res + 1;

    }
}
